// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Code generated by sidekick. DO NOT EDIT.
#![allow(rustdoc::redundant_explicit_links)]
#![allow(rustdoc::broken_intra_doc_links)]

/// Implements a client for the Data Lineage API.
///
/// # Example
/// ```
/// # tokio_test::block_on(async {
/// # use google_cloud_datacatalog_lineage_v1::client::Lineage;
/// let client = Lineage::builder().build().await?;
/// // use `client` to make requests to the Data Lineage API.
/// # gax::client_builder::Result::<()>::Ok(()) });
/// ```
///
/// # Service Description
///
/// Lineage is used to track data flows between assets over time. You can
/// create [LineageEvents][google.cloud.datacatalog.lineage.v1.LineageEvent]
/// to record lineage between multiple sources and a single target, for
/// example, when table data is based on data from multiple tables.
///
/// [google.cloud.datacatalog.lineage.v1.LineageEvent]: crate::model::LineageEvent
///
/// # Configuration
///
/// To configure `Lineage` use the `with_*` methods in the type returned
/// by [builder()][Lineage::builder]. The default configuration should
/// work for most applications. Common configuration changes include
///
/// * [with_endpoint()]: by default this client uses the global default endpoint
///   (`https://datalineage.googleapis.com`). Applications using regional
///   endpoints or running in restricted networks (e.g. a network configured
//    with [Private Google Access with VPC Service Controls]) may want to
///   override this default.
/// * [with_credentials()]: by default this client uses
///   [Application Default Credentials]. Applications using custom
///   authentication may need to override this default.
///
/// [with_endpoint()]: super::builder::lineage::ClientBuilder::with_endpoint
/// [with_credentials()]: super::builder::lineage::ClientBuilder::credentials
/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
///
/// # Pooling and Cloning
///
/// `Lineage` holds a connection pool internally, it is advised to
/// create one and the reuse it.  You do not need to wrap `Lineage` in
/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
/// already uses an `Arc` internally.
#[derive(Clone, Debug)]
pub struct Lineage {
    inner: std::sync::Arc<dyn super::stub::dynamic::Lineage>,
}

impl Lineage {
    /// Returns a builder for [Lineage].
    ///
    /// ```
    /// # tokio_test::block_on(async {
    /// # use google_cloud_datacatalog_lineage_v1::client::Lineage;
    /// let client = Lineage::builder().build().await?;
    /// # gax::client_builder::Result::<()>::Ok(()) });
    /// ```
    pub fn builder() -> super::builder::lineage::ClientBuilder {
        gax::client_builder::internal::new_builder(super::builder::lineage::client::Factory)
    }

    /// Creates a new client from the provided stub.
    ///
    /// The most common case for calling this function is in tests mocking the
    /// client's behavior.
    pub fn from_stub<T>(stub: T) -> Self
    where
        T: super::stub::Lineage + 'static,
    {
        Self {
            inner: std::sync::Arc::new(stub),
        }
    }

    pub(crate) async fn new(
        config: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<Self> {
        let inner = Self::build_inner(config).await?;
        Ok(Self { inner })
    }

    async fn build_inner(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::Lineage>> {
        if gaxi::options::tracing_enabled(&conf) {
            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
        }
        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
    }

    async fn build_transport(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<impl super::stub::Lineage> {
        super::transport::Lineage::new(conf).await
    }

    async fn build_with_tracing(
        conf: gaxi::options::ClientConfig,
    ) -> gax::client_builder::Result<impl super::stub::Lineage> {
        Self::build_transport(conf)
            .await
            .map(super::tracing::Lineage::new)
    }

    /// Creates new lineage events together with their parents: process and run.
    /// Updates the process and run if they already exist.
    /// Mapped from Open Lineage specification:
    /// <https://github.com/OpenLineage/OpenLineage/blob/main/spec/OpenLineage.json>.
    pub fn process_open_lineage_run_event(
        &self,
    ) -> super::builder::lineage::ProcessOpenLineageRunEvent {
        super::builder::lineage::ProcessOpenLineageRunEvent::new(self.inner.clone())
    }

    /// Creates a new process.
    pub fn create_process(&self) -> super::builder::lineage::CreateProcess {
        super::builder::lineage::CreateProcess::new(self.inner.clone())
    }

    /// Updates a process.
    pub fn update_process(&self) -> super::builder::lineage::UpdateProcess {
        super::builder::lineage::UpdateProcess::new(self.inner.clone())
    }

    /// Gets the details of the specified process.
    pub fn get_process(&self) -> super::builder::lineage::GetProcess {
        super::builder::lineage::GetProcess::new(self.inner.clone())
    }

    /// List processes in the given project and location. List order is descending
    /// by insertion time.
    pub fn list_processes(&self) -> super::builder::lineage::ListProcesses {
        super::builder::lineage::ListProcesses::new(self.inner.clone())
    }

    /// Deletes the process with the specified name.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn delete_process(&self) -> super::builder::lineage::DeleteProcess {
        super::builder::lineage::DeleteProcess::new(self.inner.clone())
    }

    /// Creates a new run.
    pub fn create_run(&self) -> super::builder::lineage::CreateRun {
        super::builder::lineage::CreateRun::new(self.inner.clone())
    }

    /// Updates a run.
    pub fn update_run(&self) -> super::builder::lineage::UpdateRun {
        super::builder::lineage::UpdateRun::new(self.inner.clone())
    }

    /// Gets the details of the specified run.
    pub fn get_run(&self) -> super::builder::lineage::GetRun {
        super::builder::lineage::GetRun::new(self.inner.clone())
    }

    /// Lists runs in the given project and location. List order is descending by
    /// `start_time`.
    pub fn list_runs(&self) -> super::builder::lineage::ListRuns {
        super::builder::lineage::ListRuns::new(self.inner.clone())
    }

    /// Deletes the run with the specified name.
    ///
    /// # Long running operations
    ///
    /// This method is used to start, and/or poll a [long-running Operation].
    /// The [Working with long-running operations] chapter in the [user guide]
    /// covers these operations in detail.
    ///
    /// [long-running operation]: https://google.aip.dev/151
    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
    pub fn delete_run(&self) -> super::builder::lineage::DeleteRun {
        super::builder::lineage::DeleteRun::new(self.inner.clone())
    }

    /// Creates a new lineage event.
    pub fn create_lineage_event(&self) -> super::builder::lineage::CreateLineageEvent {
        super::builder::lineage::CreateLineageEvent::new(self.inner.clone())
    }

    /// Gets details of a specified lineage event.
    pub fn get_lineage_event(&self) -> super::builder::lineage::GetLineageEvent {
        super::builder::lineage::GetLineageEvent::new(self.inner.clone())
    }

    /// Lists lineage events in the given project and location. The list order is
    /// not defined.
    pub fn list_lineage_events(&self) -> super::builder::lineage::ListLineageEvents {
        super::builder::lineage::ListLineageEvents::new(self.inner.clone())
    }

    /// Deletes the lineage event with the specified name.
    pub fn delete_lineage_event(&self) -> super::builder::lineage::DeleteLineageEvent {
        super::builder::lineage::DeleteLineageEvent::new(self.inner.clone())
    }

    /// Retrieve a list of links connected to a specific asset.
    /// Links represent the data flow between **source** (upstream)
    /// and **target** (downstream) assets in transformation pipelines.
    /// Links are stored in the same project as the Lineage Events that create
    /// them.
    ///
    /// You can retrieve links in every project where you have the
    /// `datalineage.events.get` permission. The project provided in the URL
    /// is used for Billing and Quota.
    pub fn search_links(&self) -> super::builder::lineage::SearchLinks {
        super::builder::lineage::SearchLinks::new(self.inner.clone())
    }

    /// Retrieve information about LineageProcesses associated with specific
    /// links. LineageProcesses are transformation pipelines that result in data
    /// flowing from **source** to **target** assets. Links between assets
    /// represent this operation.
    ///
    /// If you have specific link names, you can use this method to
    /// verify which LineageProcesses contribute to creating those links.
    /// See the
    /// [SearchLinks][google.cloud.datacatalog.lineage.v1.Lineage.SearchLinks]
    /// method for more information on how to retrieve link name.
    ///
    /// You can retrieve the LineageProcess information in every project where you
    /// have the `datalineage.events.get` permission. The project provided in the
    /// URL is used for Billing and Quota.
    ///
    /// [google.cloud.datacatalog.lineage.v1.Lineage.SearchLinks]: crate::client::Lineage::search_links
    pub fn batch_search_link_processes(&self) -> super::builder::lineage::BatchSearchLinkProcesses {
        super::builder::lineage::BatchSearchLinkProcesses::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn list_operations(&self) -> super::builder::lineage::ListOperations {
        super::builder::lineage::ListOperations::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn get_operation(&self) -> super::builder::lineage::GetOperation {
        super::builder::lineage::GetOperation::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn delete_operation(&self) -> super::builder::lineage::DeleteOperation {
        super::builder::lineage::DeleteOperation::new(self.inner.clone())
    }

    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
    ///
    /// [google.longrunning.Operations]: longrunning::client::Operations
    pub fn cancel_operation(&self) -> super::builder::lineage::CancelOperation {
        super::builder::lineage::CancelOperation::new(self.inner.clone())
    }
}
